package com.qfmy.project.quartz;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 描述:
 *      多线程定时任务测试类
 * @注释:
 *      Component注解说明：将该类纳入spring bean管理
 *      Async注解说明：开启多线程
 *      Scheduled注解说明：定时任务设置时间
 *
 * @author zhengjt
 * @date 2022-07-26 15:11:30
 */
@Slf4j
@Component
public class TestThreadJobs {

//    @Async("async")
//    @Scheduled(cron = "*/5 * * * * ?")
    public void threadAsync1() throws InterruptedException {
        log.info(" ================= 测试线程1 ================ ");
        for (int i = 0 ; i <= 3; i++) {
            Thread.sleep(2000);
            log.info("测试线程1： {} , 执行异步任务：{}", Thread.currentThread().getName(), i);
        }
    }

//    @Async("async")
//    @Scheduled(cron = "*/3 * * * * ?")
    public void threadAsync2() throws InterruptedException {
        log.info(" ================= 测试线程2 ================ ");
        for (int i = 0 ; i <= 3; i++) {
            Thread.sleep(2000);
            log.info("测试线程2： {} , 执行异步任务：{}", Thread.currentThread().getName(), i);
        }
    }
}
